package com.ruoyi.cabinets.controller;

import com.ruoyi.cabinets.domain.Cabinets;
import com.ruoyi.cabinets.service.ICabinetsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 柜体信息Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/cabinets/cabinets")
public class CabinetsController extends BaseController
{
    @Autowired
    private ICabinetsService cabinetsService;

    /**
     * 查询柜体信息列表
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cabinets cabinets)
    {
        startPage();
        List<Cabinets> list = cabinetsService.selectCabinetsList(cabinets);
        return getDataTable(list);
    }

    /**
     * 导出柜体信息列表
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:export')")
    @Log(title = "柜体信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cabinets cabinets)
    {
        List<Cabinets> list = cabinetsService.selectCabinetsList(cabinets);
        ExcelUtil<Cabinets> util = new ExcelUtil<Cabinets>(Cabinets.class);
        util.exportExcel(response, list, "柜体信息数据");
    }

    /**
     * 获取柜体信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:query')")
    @GetMapping(value = "/{cabinetId}")
    public AjaxResult getInfo(@PathVariable("cabinetId") String cabinetId)
    {
        return success(cabinetsService.selectCabinetsByCabinetId(cabinetId));
    }

    /**
     * 新增柜体信息
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:add')")
    @Log(title = "柜体信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cabinets cabinets)
    {
        return toAjax(cabinetsService.insertCabinets(cabinets));
    }

    /**
     * 修改柜体信息
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:edit')")
    @Log(title = "柜体信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cabinets cabinets)
    {
        return toAjax(cabinetsService.updateCabinets(cabinets));
    }

    /**
     * 删除柜体信息
     */
    @PreAuthorize("@ss.hasPermi('cabinets:cabinets:remove')")
    @Log(title = "柜体信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cabinetIds}")
    public AjaxResult remove(@PathVariable String[] cabinetIds)
    {
        return toAjax(cabinetsService.deleteCabinetsByCabinetIds(cabinetIds));
    }
}
